package com.go.where.manager.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.go.where.manager.common.Constants;
import com.go.where.manager.dao.ProjectCrowdDao;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.pojo.ProjectCrowdInfo;
import com.go.where.manager.pojo.user.UserInfoVO;
import com.go.where.manager.service.ProjectCrowdService;

@Service("projectCrowdService")
public class ProjectCrowdServiceImpl implements ProjectCrowdService {

	@Resource(name = "projectCrowdDao")
	private ProjectCrowdDao projectCrowdDao;

	@Override
	public ProjectCrowdInfo queryByPrimartKey(String cid) {
		return projectCrowdDao.getByKey(cid);
	}

	@Override
	public Pagination<ProjectCrowdInfo> queryPage(
			ProjectCrowdInfo projectCrowdInfo) {
		Integer count = projectCrowdDao.totalCount(projectCrowdInfo);
		projectCrowdInfo.calculate();
		List<ProjectCrowdInfo> list = projectCrowdDao
				.queryList(projectCrowdInfo);
		Pagination<ProjectCrowdInfo> page = projectCrowdDao.queryPagination(
				count, list, projectCrowdInfo);
		return page;
	}

	@Override
	public int save(ProjectCrowdInfo projectCrowdInfo, UserInfoVO currentUser) {
		projectCrowdInfo.setPublishTime(new Date());
		projectCrowdInfo.setUserId(currentUser.getUserId());
		projectCrowdInfo.setIsDelete(Constants.NOT_DELETED);
		return projectCrowdDao.insert(projectCrowdInfo);
	}

	@Override
	public int update(ProjectCrowdInfo projectCrowdInfo, UserInfoVO currentUser) {
		projectCrowdInfo.setUpdateTime(new Date());
		projectCrowdInfo.setUserId(currentUser.getUserId());
		return projectCrowdDao.update(projectCrowdInfo);
	}

}
